/*
 * Copyright 2014 JootMir Project
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Support: http://www.jootmir.org
 */
package org.jootmir.client.core.exception;

public class JMir2Exception extends RuntimeException {

	/** 异常类型：计算错误 */
	public static final byte EXCEPTION_TYPE_CALC = 1;
	/** 异常类型：文件读取 */
	public static final byte EXCEPTION_TYPE_FILESTREAM = 2;
	/** 异常类型：网络连接 */
	public static final byte EXCEPTION_TYPE_INTERNET = 4;
	/** 异常类型：服务端验证 */
	public static final byte EXCEPTION_TYPE_VALID = 8;
	/** 异常类型：软硬件环境 */
	public static final byte EXCEPTION_TYPE_ENV = 16;
	
	private static final long serialVersionUID = -3897877890823212103L;

	/** 构建异常 */
	public static JMir2Exception valueOf(Throwable target, byte type) {
		String message = null;
		switch(type) {
		case EXCEPTION_TYPE_CALC:
			message = "计算错误";
			break;
		case EXCEPTION_TYPE_FILESTREAM:
			message = "文件读取错误";
			break;
		case EXCEPTION_TYPE_INTERNET:
			message = "网络连接错误";
			break;
		case EXCEPTION_TYPE_VALID:
			message = "服务端验证错误";
			break;
		case EXCEPTION_TYPE_ENV:
			message = "软硬件环境错误";
			break;
			default:
				message = "未知异常！";
		}
		return new JMir2Exception(message, target);
	}
	
	/* 构造函数 */
	public JMir2Exception() {}
	public JMir2Exception(String message, Throwable cause) {
		super(message, cause);
	}
}